package com.xwli.webservice.conf;

import com.xwli.webservice.cxf.service.impl.CxfWebServiceDemoImpl;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.xml.ws.Endpoint;

/**
 * @author xwli
 * @date: 2021/10/18 15:37
 * @desc
 * @since JDK 1.8
 */

@Configuration
public class CxfWebServicePublishConfig {

    @Autowired
    private CxfWebServiceDemoImpl cxfWebServiceDemo;

    @Bean
    public ServletRegistrationBean cxfServlet() {
        return new ServletRegistrationBean(new CXFServlet(), "/ws/*");
    }

    @Bean(name = Bus.DEFAULT_BUS_ID)
    public SpringBus springBus() {
        return new SpringBus();
    }

    /**
     * cxf框架webservice发布
     * @return
     */
    @Bean
    public Endpoint gcsgEndpoint() {
        EndpointImpl endpoint = new EndpointImpl(springBus(), cxfWebServiceDemo);
        endpoint.publish("/cxfWebServiceDemo");
        return endpoint;
    }

}

